﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Halk.Dao;
using Halk.Model;

namespace Halk.Spider
{
    public class SysManage
    {
        private static SysManage _sysManage;

        public static  SysManage Instace()
        {
            return _sysManage ?? (_sysManage = new SysManage());
        }

        private readonly Dao.DaoSysWeb _daoSysWeb = new DaoSysWeb(Config.ConfigManage.Instace().GetConfig().ConnString);

        private Dictionary<string, SysWebInfo> _dicSysWebs;

        private void LoadSysWebs()
        {
            if (_dicSysWebs == null)
                _dicSysWebs = new Dictionary<string, SysWebInfo>();

            var list = _daoSysWeb.GetList();
            foreach (SysWebInfo sysWebInfo in list)
            {
                if (!_dicSysWebs.ContainsKey(sysWebInfo.webflag))
                    _dicSysWebs[sysWebInfo.webflag] = sysWebInfo;
            }
        }

        public SysWebInfo GetSysWeb(string flag)
        {
            if(_dicSysWebs==null||_dicSysWebs.Count==0)
            {
                LoadSysWebs();
            }
            return _dicSysWebs != null ? _dicSysWebs[flag] : null;
        }
    }
}
